import { BasicColumn, FormSchema } from '@/components/Table';
import { h, ref } from 'vue';
import { Tag } from 'ant-design-vue';
import { ywUserSelectList } from '@/api/heng/ywManage';
import { ApiSelect } from '@/components/Form';
import util from '@/utils/util';

import { useMessage } from '@/hooks/web/useMessage';
import Ainput from '@/views/bookManage/components/account/Ainput.vue';
import { VxeFormItemProps, VxeGridPropTypes } from '@/components/VxeTable';
import { changeEnd } from 'codemirror';
import { paperSelectList } from '@/api/heng/ex';

type CheckedType = boolean | string | number;
// BasicColumn[]

// VxeColumnPropTypes.CellRender

/**
 */
export const vxeTableColumns: VxeGridPropTypes.Columns = [
  {
    title: '试卷名称',
    field: 'paperName',
    showOverflow: 'title',
  },

  {
    title: '考试状态',
    field: 'status',
    showOverflow: 'title',
    align: 'center',
    formatter: ({ cellValue, row, column }) => {
      let val = '';
      let color="";
      switch (cellValue) {
        case 0:
          val = '未开始';
          break;
        case 1:
          color='orange';
          val = '进行中';
          break;
        case 2:
          val = '已结束';
          break;
      }
      return val;// h(Tag, { color: color }, () => val)
    },
    width: 90,
  },
  {
    title: '预计开考时间',
    field: 'startTime',
    width: 180,
    align: 'center',
  },
  {
    title: '创建时间',
    field: 'createTime',
    width: 180,
    align: 'center',
  },
  {
    width: 250,
    title: '操作',
    align: 'center',
    field: '',
    slots: { default: 'action' },
    fixed: 'right',
  },
];

export const vxeTableFormSchema: VxeFormItemProps[] = [
  {
    span: 5,
    field: 'keyword',
    title: '查询',
    itemRender: {
      props: {
        placeholder: '查询',
      },
      name: 'AInput',
    },
  },
  {
    span: 5,
    field: 'active',
    title: '是否启用',
    itemRender: {
      defaultValue: 1,
      props: {
        placeholder: '请选择',
        style: { width: '100%' },
        options: [
          { label: '是', value: 1 },
          { label: '否', value: 0 },
        ],
      },
      name: 'ASelect',
    },
  },
  {
    span: 5,
    itemRender: {
      name: 'VxeButtonGroup',
      options: [
        { type: 'reset', content: '重置' },
        { type: 'submit', content: '查询', status: 'primary' },
      ],
    },
  },
];



export const addformSchema: FormSchema[] = [
  {
    label: '试卷名称',
    field: 'paperId',
    component: 'ApiSelect',
    componentProps:{
      mode:"single",
      resultField:'data',
      labelField:'name',
      valueField:'paperId',
      api:paperSelectList
    },
    required: true,
  },
  {
    field: 'startTime',
    label: '预计开考时间',
    component: 'DatePicker',
    componentProps: {
      showTime:true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      format: 'YYYY-MM-DD HH:mm:ss',
    },
    required: false,
  },


];


export const formSchema: FormSchema[] = [
  {
    label: '试卷名称',
    field: 'name',
    component: 'Input',
    required: true,
  },
  {
    field: 'model',
    label: '考试模式',
    component: 'Select',
    componentProps: {
      options: [
        { label: '单一模块', value: 1 },
        // { label: '整张试卷', value: 2 },
      ],
    },
    required: true,
  },
  {
    field: 'limitTime',
    label: '考试分钟数',
    component: 'InputNumber',
    required: true,
  },

];




export const titleGroupColumns: VxeGridPropTypes.Columns = [
  {
    title: '分类',
    field: 'categoryName',
    showOverflow: 'title',
    align: 'center',
    editRender:{
      name: 'VxeInput',
    },
  },
  {
    title: '考试模式',
    field: 'model',
    showOverflow: 'title',
    align: 'center',
    width: 140,
    formatter: ({ cellValue, row, column }) => {
      let val = '';
      if (!cellValue) {
        return val;
      }
      switch (cellValue) {
        case 1:
          val = '单一模块';
          break;
        case 2:
          val = '整张试卷';
          break;
      }
      return val;
    },
  },
  {
    title: '考试状态',
    field: 'status',
    showOverflow: 'title',
    align: 'center',
    width: 140,
    formatter: ({ cellValue, row, column }) => {
      let val = '';
      let color="";
      switch (cellValue) {
        case 0:
          color='orange';
          val = '未开始';
          break;
        case 1:
          color='orange';
          val = '进行中';
          break;
        case 2:
          color='red';
          val = '已结束';
          break;
      }
      // row.color=color;
      return val;
    },
  },
  {
    title: '考试分钟数',
    field: 'limitTime',
    showOverflow: 'title',
    align: 'center',
    editRender:{
      name: 'VxeNumberInput',
    },
    width: 100
  },
  {
    title: '预计开考时间',
    field: 'planStartTime',
    showOverflow: 'title',
    align: 'center',
    width: 150
  },
  {
    title: '预计结束时间',
    field: 'planEndTime',
    showOverflow: 'title',
    align: 'center',
    width: 150
  },
  {
    title: '实际开考时间',
    field: 'startTime',
    showOverflow: 'title',
    align: 'center',
    width: 150
  },
  {
    title: '实际结束时间',
    field: 'endTime',
    showOverflow: 'title',
    align: 'center',
    width: 150
  },
  {
    width: 180,
    title: '操作',
    align: 'center',
    field: '',
    slots: { default: 'action' },
    fixed: 'right',
  },
];

export const chooseQuestionColumns: VxeGridPropTypes.Columns = [
  // {
  //   type: 'checkbox',
  //   title: '',
  //   field: 'seq',
  //   width: 40,
  // },
  {
    title: '类型',
    field: 'type',
    showOverflow: 'title',
    align: 'center',
    width: 140,
  },

  {
    title: '题目内容',
    field: 'title',
    showOverflow: 'title',
  },


  {
    title: '选项',
    field: 'letter',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },
  {
    title: '正确选项',
    field: 'isTrue',
    showOverflow: 'title',
    align: 'center',
    width: 100,
    formatter: ({ cellValue, row, column }) => {
      let val = '';
      switch (cellValue) {
        case 0:
          val = '否';
          break;
        case 1:
          val = '是';
          break;

      }
      // row.color=color;
      return val;
    },
  },
];

export const titleGroupform: FormSchema[] = [
  {
    field: 'categoryId',
    label: '分类',
    required: true,
    slot: 'categoryId',
    // component: 'ApiTreeSelect',
    // componentProps: {
    //   resultField: 'data',
    //   labelField: 'categoryName',
    //   valueField: 'categoryId',
    //   childrenField: 'children',
    //   params: { status: 1 },
    //   api: categoryList,
    // },
  },
  {
    field: 'categoryName',
    label: 'categoryName',
  },
  {
    field: 'type',
    label: '选题类型',
    component: 'Select',
    componentProps: {
      options: [
        { label: '部分', value: 1 },
        { label: '全部', value: 0 },
      ],
    },
  },
  {
    field: 'startTime',
    label: '开考时间',
    component: 'TimePicker',
    required: true,
    componentProps: {
      valueFormat:'HH:mm:ss',
      format:"HH:mm:ss"
    },
  },
  {
    field: 'partQuestions',
    label: '已选题目',
    required: false,
    slot: 'question_select',
    colProps: { lg: 24, md: 24 },
    ifShow: ({ values }) => values.type === 1,
  },
  {
    field: 'all_questions',
    label: '全部题目',
    required: false,
    slot: 'all_questions',
    // colProps: { lg: 24, md: 24 },
    ifShow: ({ values }) => values.type === 0,
  },
];


/**
 * 用户答题情况
 */
export const userAnsersColumns: VxeGridPropTypes.Columns = [
  // {
  //   title: '展开选项',
  //   field: 'options',
  //   type: 'expand',
  //   width: 60,
  //   slots: { content: 'expand_content' }
  // },
  // {
  //   title: '试卷',
  //   field: 'paperName',
  //   width: 130,
  //   showOverflow: 'title',
  //   align: 'center',
  // },
  {
    title: '分组',
    field: 'groupName',
    showOverflow: 'title',
    width: 60,
  },
  {
    title: '序号',
    type: 'seq',
    fixed: 'left',
    width: 50,
    align: 'center',
  },
  {
    title: '人员',
    field: 'userName',
    showOverflow: 'title',
    filters: [{ data: '' }],
    filterRender: {
      name: 'VxeInput',
    },
    align: 'center',
    width: 100,
  },

  {
    title: '题目类型',
    field: 'type',
    showOverflow: 'title',
    width: 100,
  },
  {
    title: '模块',
    field: 'publishGroupName',
    showOverflow: 'title',
    width: 100,
  },
  {
    title: '题目序号',
    field: 'sort',
    showOverflow: 'title',
    width: 70,
    formatter: ({ cellValue, row, column }) => {
      let val = cellValue;
      if (!row.stateName) {
        return val;
      }
      val ++;
      return val;
    },
  },

  // {
  //   title: '选项',
  //   field: 'letter',
  //   showOverflow: 'title',
  //   align: 'center',
  //   width: 100,
  // },
  {
    title: '题目内容',
    field: 'title',
    filters: [{ data: '' }],
    filterRender: {
      name: 'VxeInput',
    },
    showOverflow: 'title',
  },
  {
    title: '所有选项',
    field: 'allOptions',
    width: 250,
    formatter: ({ cellValue, row, column }) => {
      let val = '';
      if(row.allOptions){
        let arr=[];
        row.allOptions.forEach(e=>{
          arr.push(e.letter+":"+e.title);
        })
        val = arr.join(";")
      }
      // row.color=color;
      return val;
    },
    showOverflow: 'title',
  },
  {
    title: '考生选择',
    field: 'options',
    width: 100,
    formatter: ({ cellValue, row, column }) => {
      let val = '';
      if(row.options){
        let arr=[];
        row.options.forEach(e=>{
          arr.push(e.letter+":"+e.title);
        })
        val = arr.join(";")
      }else if(!row.groupName){
        val = '未答';
      }
      // row.color=color;
      return val;
    },
    showOverflow: 'title',
  },

  {
    title: '是否答对',
    field: 'isTrue',
    showOverflow: 'title',
    align: 'center',
    width: 70,
    filters: [
      { label: '正确', value: 1 },
      { label: '错误', value: 0 },
    ],
    formatter: ({ cellValue, row, column }) => {
      let val = '';
      switch (cellValue) {
        case 0:
          val = '错误';
          break;
        case 1:
          val = '正确';
          break;

      }
      // row.color=color;
      return val;
    },
  },
  {
    title: '是否有答题',
    field: 'haveAnser',
    showOverflow: 'title',
    align: 'center',
    width: 70,
    filters: [
      { label: '有', value: 1 },
      { label: '无', value: 0 },
    ],
    formatter: ({ cellValue, row, column }) => {
      let val = '';
      switch (cellValue) {
        case 0:
          val = '无';
          break;
        case 1:
          val = '有';
          break;

      }
      // row.color=color;
      return val;
    },
  },
  {
    title: '得分情况',
    field: 'score',
    showOverflow: 'title',
    width: 70,
    formatter: ({ cellValue, row, column }) => {
      let val = cellValue;
      let l="";
      switch (row.isTrue) {
        case 0:
          l="-";
          break
        case 1:
          l="+";
          break
      }

      return `${l}${val?val:0}`;
    },
  },
];
